<?php

class CmspagesController extends AppController {

    var $name = 'Cmspages';
    var $helpers = array('Html', 'Form', 'Javascript', 'Fck');

    function beforeFilter() {
        parent::beforeFilter();
    }

    function index() {
        $this->Cmspage->recursive = 0;
        $this->set('cmspages', $this->paginate());
    }

    function view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid cmspage', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->set('cmspage', $this->Cmspage->read(null, $id));
    }

    function add() {
        $this->layout = null;
        if (!empty($this->data)) {
            $this->data['Cmspage']['modified'] = date('Y-m-d H:i:s');
            $this->Cmspage->create();
            if ($this->Cmspage->save($this->data)) {
                $this->Session->setFlash(__('The Page has been saved', true));
                $this->redirect(array('action' => 'backstage_index'));
            } else {
                //$this->Session->setFlash(__('The cmspage could not be saved. Please, try again.', true));
            }
        }
    }

    function edit($id = null) {
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid cmspage', true));
            $this->redirect(array('action' => 'index'));
        }
        if (!empty($this->data)) {
            $this->data['Cmspage']['modified'] = date('Y-m-d H:i:s');
            if ($this->Cmspage->save($this->data)) {
                $this->render('updatesuccess');
            } else {
                //$this->Session->setFlash(__('The cmspage could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->Cmspage->read(null, $id);
        }
    }

    function delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for cmspage', true));
            $this->redirect(array('action' => 'index'));
        }
        if ($this->Cmspage->delete($id)) {
            $this->Session->setFlash(__('Cmspage deleted', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('Cmspage was not deleted', true));
        $this->redirect(array('action' => 'index'));
    }

    function backstage_index() {
        $this->layout = 'admin';
        $this->Cmspage->recursive = 0;
        $this->set('cmspages', $this->paginate());
    }

    function backstage_view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid cmspage', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->set('cmspage', $this->Cmspage->read(null, $id));
    }

    function backstage_add() {
        $this->layout = 'admin';
        if (!empty($this->data)) {
            $this->data['Cmspage']['modified'] = date('Y-m-d H:i:s');
            $this->Cmspage->create();
            if ($this->Cmspage->save($this->data)) {
                $this->Session->setFlash(__('The page has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The page could not be saved. Please, try again.', true));
            }
        }
    }

    function backstage_edit($id = null) {
        $this->layout = 'admin';
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid page', true));
            $this->redirect(array('action' => 'index'));
        }
        if (!empty($this->data)) {
            if ($this->Cmspage->save($this->data)) {
                $this->Session->setFlash(__('The page has been Updated', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The page could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->Cmspage->read(null, $id);
        }
    }

    function backstage_delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for page', true));
            $this->redirect(array('action' => 'index'));
        }
        if ($this->Cmspage->delete($id)) {
            $this->Session->setFlash(__('The Page deleted', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('The Page was not deleted', true));
        $this->redirect(array('action' => 'index'));
    }

}

?>